<?php

/**
 * This is the model class for table "tbl_vacationhrs".
 *
 * The followings are the available columns in table 'tbl_vacationhrs':
 * @property integer $id
 * @property string $empno
 * @property string $hours
 * @property string $notes
 * @property string $dateadded
 * @property string $addedby
 * @property string $datetaken
 */
class Vacationhrs extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Vacationhrs the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_vacationhrs';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('empno, hours, datetaken', 'required'),
                        array('notes','length','max'=>9999999),
			array('empno, hours', 'length', 'max'=>4),
			array('addedby', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, empno, hours, notes, dateadded, addedby, datetaken', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'empno' => 'Employee Number',
			'hours' => 'Hours',
			'notes' => 'Notes',
			'dateadded' => 'Date added',
			'addedby' => 'Added By',
			'datetaken' => 'Date Taken',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
		
		$criteria->compare('id',$this->id);
		$criteria->compare('empno',$this->empno,true);
		$criteria->compare('hours',$this->hours,true);
		$criteria->compare('notes',$this->notes,true);
		$criteria->compare('dateadded',$this->dateadded,true);
		$criteria->compare('addedby',$this->addedby,true);
		$criteria->compare('datetaken',$this->datetaken,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        public function beforeValidate() {
            parent::beforeValidate();
            $this->addedby=Yii::app()->user->name;
            $this->dateadded=DateUtil::getDefaultCurrentDateTime();
            return true;
        }
}